class NewsController < ApplicationController
	def index
		@category = Category.find_by_id(params[:category_id])
		if @category
			@news = New.paginate_by_sql("SELECT n.* FROM news n JOIN categories_news c on n.id=c.new_id WHERE c.category_id=#{@category.id} ORDER BY n.created_at DESC",:per_page => 10, :page => params[:page])
		else
			@news = New.paginate(:per_page => 10, :page => params[:page], :order => "created_at DESC")
		end
	end

	def show 
		@category = Category.find_by_id(params[:category_id])
		@news = New.find_by_id(params[:id])
	end
end
